package com.copa.l1814;

import java.util.HashMap;
import java.util.Map;

/**
 * @author copa
 * @createDate 2023-01-17 10:17
 * @function 哈希表+公式转换法
 */
public class Test3 {

    public int countNicePairs(int[] nums) {
        final int MOD = 1000000007;
        int result = 0;
        Map<Integer, Integer> map = new HashMap<>();
        int tempSum;
        for (int num : nums) {
            tempSum = num - reverseNum(num);
            result = (result + map.getOrDefault(tempSum, 0)) % MOD;
            map.put(tempSum, map.getOrDefault(tempSum, 0) + 1);
        }
        return result;
    }

    public Integer reverseNum(int num) {
        int result = 0;
        while (num > 0) {
            result = num % 10 + result * 10;
            num /= 10;
        }
        return result;
    }

    public static void main(String[] args) {
        //int[] nums = {42,11,1,97};
        int[] nums = {13,10,35,24,76};
        System.out.println(new Test3().countNicePairs(nums));
    }
}
